cmake_minimum_required(VERSION 3.22)
project(mediatools)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_PREFIX_PATH "D:/Applications/QT/5.10.1/mingw53_32")

#引入头文件
include_directories(
        ${PROJECT_SOURCE_DIR}/Sources/Headers
)
#引入头文件
include_directories(${PROJECT_SOURCE_DIR}/ffmpeg-4.2.1-win32-dev/include)
#引入库文件
link_directories(${PROJECT_SOURCE_DIR}/ffmpeg-4.2.1-win32-dev/lib)



find_package(Qt5 COMPONENTS
        Core
        Gui
        Widgets
        REQUIRED)

add_executable(mediatools Sources/main.cpp Sources/mainwindow.cpp Sources/Headers/mainwindow.h Sources/Forms/mainwindow.ui Sources/dumpvideownd.cpp Sources/Headers/dumpvideownd.h Sources/Forms/dumpvideownd.ui Sources/extractaudiownd.cpp Sources/Headers/extractaudiownd.h Sources/Forms/extractaudiownd.ui Sources/extractvideownd.cpp Sources/Headers/extractvideownd.h Sources/Forms/extractvideownd.ui Sources/encodewnd.cpp Sources/Headers/encodewnd.h Sources/Forms/encodewnd.ui Sources/playerwnd.cpp Sources/Headers/playerwnd.h Sources/Forms/playerwnd.ui)
target_link_libraries(mediatools avformat.lib
        avcodec.lib avcodec.lib avutil.lib
        avdevice.lib avfilter.lib
        postproc.lib swresample.lib swscale.lib
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        )

if (WIN32)
    set(DEBUG_SUFFIX)
    if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
        set(DEBUG_SUFFIX "d")
    endif ()
    set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
    if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
        set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
            set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        endif ()
    endif ()
    if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E make_directory
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
    endif ()
    foreach (QT_LIB Core Gui Widgets)
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
    endforeach (QT_LIB)
endif ()
